package com.awspaas.user.apps.cpq.job;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.cpq.util.RefreshDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshModulDataUtils;
import com.awspaas.user.apps.cpq.util.RefreshTempDataUtils;

public class UpdateOutsourcingJob implements IJob{

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		try {
			/**
			 * 更新外协价格维护表
			 */
			List<BO>bos=SDK.getBOAPI().query("BO_EU_CPQ_OUTSOURCING").addQuery("SFTJ=","1").list();
			if(bos.size()>0) {
				  Map<String, JSONObject> userMap = new HashMap<String, JSONObject>();
				    String bms = "";
					List<String> bhList = new ArrayList<>();
					for (BO bo : bos) {
						String bm = bo.getString("BM");
						JSONObject json = new JSONObject();
						json.put("QTFY", bo.getString("QTFY"));
						json.put("BM", bm);
						bhList.add(bm);
						userMap.put(bm, json);
						SDK.getBOAPI().updateByBindId("BO_EU_CPQ_OUTSOURCING", bo.getBindId(), "SFTJ", "");
					}
					/**
					 * 1、获取需要更新的制造件和装配件信息
					 */
					
					Map<String, JSONObject> comtMap=RefreshDataUtils.outsourcingRefreshAssembly‌(userMap);
					/**
					 * 2、获取需要更新的模块信息
					 * 
					 */
					
				   Map<String, Map<String, Object>> modulLists=RefreshModulDataUtils.outsourcingRefreshModule(comtMap);
					/**
					 * 3、获取需要更新的项目报价记录台账中类型为模板的数据
					 * 
					 */	
				 
					RefreshTempDataUtils.updateTempByOutsourcing‌(modulLists);	
					
			}
		} catch (Exception e) {
		  throw  e;
		}
		
	}

}
